package com.javiercp.ayudaapp.preferences;

import android.os.Build;
import android.preference.PreferenceCategory;

public abstract class ContactsPreferenceInflater {
	
	private static ContactsPreferenceInflater mInstance;
	
	public static ContactsPreferenceInflater getInstance() {
		if (mInstance == null) {
			String className;
			
			int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
			if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
				//TODO: verificar compatibilidad
				className = "ContactsPreferenceInflaterSDK5";
			}
			else {
				className = "ContactsPreferenceInflaterSDK5";
			}
			
			try {
				Class<? extends ContactsPreferenceInflater> myClass = 
					Class.forName(ContactsPreferenceInflater.class.getPackage().getName() + "." + className).asSubclass(ContactsPreferenceInflater.class);
				
				mInstance = myClass.newInstance();
			} catch (Exception e) {
				throw new IllegalStateException(e);
			}
		}
		
		return mInstance;
	}
	
	public abstract void inflate(String xml, PreferenceCategory pref);
	public abstract ContactDataList deserialice(String xml);
}
